// ==================================================================================
// Shared Genomics Project MPI Codebase
// Version 1.0 30/04/2010
//
// (c) 2010 University of Manchester all rights reserved
//
// This file is distributed under the GNU General Public License, Version 2.  
// Please see the file COPYING.txt for more details
// ==================================================================================

#ifndef _CSNP_H_
#define _CSNP_H_

#include <stdio.h>

#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
\file
\ingroup	gio
\brief		SNP-Major Allelic Data Storage (PLINK)
\details
	This header provides methods to store allelic data.<br> 
	It is based on a PLINK csnp class and allelic information is stored as boolean arrays.<br>
	The \ref csnp structure is used to store allelic information read from PLINK-compatible
	text input files.<br>
	The \ref csnp structure  is not involved in any of the statistical calculations where
	allelic data is stored in a more compact a bitstring format.<br>
*/

/*! \brief SNP-Major Allelic Data Storage (PLINK) */
struct csnp {
	/*! \brief Array of each person's allelic data at position 1. */
	BOOL *one;

	/*! \brief Array of person's allelic data at position 2. */
	BOOL *two;

	/*! \brief Size of the position one array */
	int nOne;
	
	/*! \brief Size of the position two array */
	int nTwo;

	/*! \brief Data Input counter for position one. */
	int currentOneIndex; 

	/*! \brief Data Input counter for position two. */
	int currentTwoIndex;
};

/*! 
\brief Initialise a csnp structure 
\details Arrays set to NULL, counters to zero.
\param [in,out] c Structure to initialise
\returns 1 on success, 0 on failure.
*/
int csnp_init(struct csnp* c);

/*! 
\brief Create an initialised a csnp structure 
\returns one \ref csnp or NULL on failure
*/
struct csnp* csnp_create();

/*! 
\brief De-allocate csnp attributes.
\details 
	Simply frees the csnp::one and csnp::two arrays and resets 
	the appropriate counters.
\returns 1 on success, 0 on failure.
*/
int csnp_free_attributes(struct csnp *c);

/*! 
\brief Allocate storage to allelic position one array (csnp::one).
\param [in,out] c csnp Structure
\param [in] size No. samples/people in data-set
\returns 1 on success, 0 on failure.
*/
int csnp_alloc_one(struct csnp *c, int size);

/*! 
\brief Allocate storage to allelic position two array (csnp::two).
\param [in,out] c csnp Structure
\param [in] size No. samples/people in data-set
\returns 1 on success, 0 on failure.
*/
int csnp_alloc_two(struct csnp *c, int size);

#ifdef __cplusplus
}
#endif

#endif // _CSNP_H_
